import threading
import requests

class Donwload:
    def download(self, url, callback):
        print(f'线程：{threading.current_thread().name}开始下载{url}')
        print(f'线程：{threading.get_ident()}开始下载{url}')
        response = requests.get(url)
        response.encoding = 'utf-8'
        callback(url, response.text)

    def start_download(self, url, callback):
        thread = threading.Thread(target=self.download, args=(url, callback))
        thread.start()

def finish_download_size_count(url,result):
    print(f'{url} download finish , {len(result)}字，内容为{result[:10]}...')

def main():
    print("main thread start")
    d = Donwload()
    d.start_download("http://127.0.0.1:8000/1.txt",finish_download_size_count)
    d.start_download("http://127.0.0.1:8000/2.txt",finish_download_size_count)
    d.start_download("http://127.0.0.1:8000/3.txt",finish_download_size_count)



if __name__ == "__main__":
    main()